package com.class04.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @ClassDescription:
 * 连接池的配置类，读取连接池配置信息
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/21 11:15
 */
@Configuration
@PropertySource("classpath:jdbc.properties")
public class DataSourceJavaConfig {
    @Value("${class04.username}")
    public String username;
    @Value("${class04.password}")
    public String password;
    @Value("${class04.driver}")
    public String driver;
    @Value("${class04.url}")
    public String url;
    @Bean
    public DataSource dataSource(){
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setPassword(password);
        dataSource.setDriverClassName(driver);
        dataSource.setUsername(username);
        dataSource.setJdbcUrl(url);
        return dataSource;
    }
}
